package com.cloudkinto.service.platform.vo.rakuten;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

@Data
public class SenderModel {
    @ApiModelProperty(required = true,notes = "必填 邮编1")
    private String zipCode1;
    @ApiModelProperty(required = true, notes = "必填 邮编2")
    private String zipCode2;
    @ApiModelProperty(required = true , notes = "必填 省")
    private String prefecture;
    @ApiModelProperty(required = true, notes = "必填 市")
    private String city;
    @ApiModelProperty(required = true, notes = "必填 详细地址")
    private String subAddress;
    @ApiModelProperty(required = true , notes = "必填 姓名")
    private String familyName;
    @ApiModelProperty(required = true , notes = "必填 姓")
    private String firstName;
    @ApiModelProperty("假名")
    private String familyNameKana;
    @ApiModelProperty("假名")
    private String firstNameKana;
    @ApiModelProperty(required = true, notes = "必填 电话1")
    private String phoneNumber1;
    @ApiModelProperty(required = true, notes = "必填 电话2")
    private String phoneNumber2;
    @ApiModelProperty(required = true, notes = "必填 电话3")
    private String phoneNumber3;

    public SenderModel() {
    }

    public SenderModel(String prefecture, String city, String subAddress, String familyNameKana, String firstNameKana) {
        this.prefecture = prefecture;
        this.city = city;
        this.subAddress = subAddress;
        this.familyNameKana = familyNameKana;
        this.firstNameKana = firstNameKana;
    }

    public String getAddress() {
        StringBuilder builder = new StringBuilder();
        if (StringUtils.isNotBlank(prefecture)) {
            builder.append(prefecture);
        }
        if (StringUtils.isNotBlank(city)) {
            builder.append(city);
        }
        if (StringUtils.isNotBlank(subAddress)) {
            builder.append(subAddress);
        }

        return builder.toString();
    }

    public String getBuyerName() {
        StringBuilder builder = new StringBuilder();
        if (StringUtils.isNotBlank(firstName) && StringUtils.isNotBlank(familyName)) {
            builder.append(familyName).append(" ").append(firstName);
        }
        else if (StringUtils.isNotBlank(firstNameKana) && StringUtils.isNotBlank(familyNameKana)) {
            builder.append(familyNameKana).append(" ").append(firstNameKana);
        }
        else {
            return StringUtils.isNotBlank(firstName) ? firstName : familyName;
        }
        return builder.toString();
    }

    public String getPhoneNumber() {
        StringBuilder builder = new StringBuilder();
        if (StringUtils.isNotBlank(phoneNumber1)) {
            if (builder.length() > 0) {
                builder.append("-");
            }
            builder.append(phoneNumber1);
        }
        if (StringUtils.isNotBlank(phoneNumber2)) {
            if (builder.length() > 0) {
                builder.append("-");
            }
            builder.append(phoneNumber2);
        }
        if (StringUtils.isNotBlank(phoneNumber3)) {
            if (builder.length() > 0) {
                builder.append("-");
            }
            builder.append(phoneNumber3);
        }
        return builder.toString();
    }

    public String getZipCode() {
        StringBuilder builder = new StringBuilder();
        if (StringUtils.isNotBlank(zipCode1)) {
            if (builder.length() > 0) {
                builder.append("-");
            }
            builder.append(zipCode1);
        }
        if (StringUtils.isNotBlank(zipCode2)) {
            if (builder.length() > 0) {
                builder.append("-");
            }
            builder.append(zipCode2);
        }

        return builder.toString();
    }
}
